<template>
  <div>
    <div class="header">
      <div class="img">
        <img :src="detail.coverImgUrl" alt="" />
        <span
          ><i class="iconfont icon-24gl-play"></i> {{ detail.playCount }}
        </span>
      </div>
      <div class="text">
        <p>{{ detail.name }}</p>
        <p>
          <img :src="detail.creator.avatarUrl" alt="" />
          <span>{{ detail.creator.nickname }}</span>
          <i class="iconfont icon-jiahao2fill"></i>
        </p>
        <p>
          <span>
            {{ detail.description }}
          </span>
          <i class="iconfont icon-xiangyou1"></i>
        </p>
      </div>
    </div>
    <div class="x-middle">
      <div class="infor">
        <div>
          <i class="iconfont icon-tianjiazengjiajia"></i>
          <span>311</span>
        </div>
        <div><i class="iconfont icon-liuyan"></i> <span>10</span></div>
        <div><i class="iconfont icon-fenxiang"></i> <span>75</span></div>
      </div>
    </div>
    <div class="content">
      <div
        class="song"
        v-for="(item, index) of tracks"
        :key="item.id"
        @click="toPlay(item.id)"
      >
        <div>{{ index + 1 }}</div>
        <div>
          <img :src="item.al.picUrl" alt="" />
        </div>
        <div>
          <p>{{ item.name }}</p>
          <p>{{ item.al.name }}</p>
        </div>
        <div>
          {{ handleTime(item.dt) }}
        </div>
        <div>
          <i class="iconfont icon-bofang"></i>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      detail: {},
      tracks: [],
    };
  },
  mounted() {
    // console.log(this.$route.params);
    var { id } = this.$route.params;
    this.$http(`http://122.112.161.135:3000/playlist/detail?id=${id}`).then(
      (res) => {
        res.data.playlist.playCount =
          Math.ceil(res.data.playlist.playCount / 10000) + "万";
        this.tracks = res.data.playlist.tracks;
        this.detail = res.data.playlist;
      }
    );
  },
  methods: {
    handleTime(time) {
      time = time / 1000;
      var m = Math.floor(time / 60);
      m = m < 10 ? "0" + m : m;
      var s = Math.floor(time % 60);
      s = s < 10 ? "0" + s : s;
      return m + ":" + s;
    },
    toPlay(val){
      this.$router.push(`/play/${val}`)
    }
  },
};
</script>

<style scoped>
.header {
  display: flex;
  color: white;
  background: #3f2f30;
}
.header > div {
  margin: 20px 0 50px 0;
}
.img i {
  font-size: 20px;
}
.img {
  width: 40%;
  position: relative;
}
.img > img {
  width: 280px;
  border-radius: 30px;
}
.img > span {
  display: inline-block;
  position: absolute;
  top: 8px;
  right: 15px;
}
.text {
  height: 260px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: rgb(180, 180, 180);
  font-size: 26px;
  padding-left: 20px;
}
.text img {
  width: 80px;
  vertical-align: middle;
  border-radius: 50%;
}
.text i {
  font-size: 30px;
}
.text p:first-child {
  font-size: 32px;
  color: white;
}
.text p:nth-child(2) span {
  display: inline-block;
  padding: 0 10px;
}
.text p:last-child span {
  width: 380px;
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.x-middle {
  width: 80%;
  margin-left: auto;
  margin-right: auto;
  font-size: 30px;
}
.x-middle i {
  font-size: 35px;
}
.x-middle .infor {
  display: flex;
  justify-content: space-around;
  border: 1px solid gainsboro;
  border-radius: 30px;
  padding: 30px 12px;
  position: relative;
  top: -35px;
  z-index: 101;
  background-color: white;
}

.infor div:not(:last-child) {
  padding: 0 12px 0 0;
  border-right: 1px solid gainsboro;
}
.content{
  width: 90%;
  margin: auto;
}
.song{
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.song>div{
  padding-top: 20px;
}
.song img{
  width: 100px;
}
.song>div:nth-child(2){
  width: 20%;
}
.song>div:nth-child(3){
  width: 35%;
}
.song>div:nth-child(4){
  width: 15%;
}
.song>div:nth-child(3) p:nth-child(1){
  font-size: 28px;
  padding-bottom: 10px;
}
.song>div:last-child i{
  font-size: 50px;
}
</style>